<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">
        <div class="layui-form layuimini-form">
            <div class="layui-form-item">
                <label class="layui-form-label">MCH_ID</label>
                <div class="layui-input-block">
                    <input type="text" name="wechatpay_mchid" maxlength="10" class="layui-input">
                    <tip>商户号ID，1开头的10位数字，从商户平台管理页面获取</tip>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">MCH_KEY</label>
                <div class="layui-input-block">
                    <input type="text" name="wechatpay_mchkey" maxlength="50" class="layui-input">
                    <tip>商户号API密钥，从商户平台管理页面获取</tip>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">接口证书</label>
                <div class="layui-input-block">
                    <input type="text" name="wechatpay_mchcert" maxlength="50" class="layui-input">
                    <tip>重要API接口所需证书，如退款、提现等（付款不需要），从商户平台管理页面获取</tip>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="saveBtn">确认保存</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use([], function () {
        var $ = layui.jquery,
            layer = layui.layer,
            http = layui.http,
            form = layui.form;

        //拉取信息
        var oldData;
        http.ajaxPost('/admin/Setting/getWechatPay', {}, function (data) {
            oldData = data;
            $("[name='wechatpay_mchid']").val(data.wechatpay_mchid);
            $("[name='wechatpay_mchkey']").val(data.wechatpay_mchkey);
            $("[name='wechatpay_mchcert']").val(data.wechatpay_mchcert);
        });

        //监听提交
        form.on('submit(saveBtn)', function (formdata) {
            for (let field in formdata.field) {
                if (formdata.field[field] == oldData[field]) {
                    delete formdata.field[field];
                }
            }
            http.ajaxPost('/admin/Setting/saveWechatPay', formdata.field, function (data) {
                for (let field in formdata.field) {
                    oldData[field] = formdata.field[field];
                }
                layer.msg('保存成功', { time: 1000 }, function () { });
            });
        });
    });
</script>